using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_StockManage_StockInManage : Member, IRequiresSessionState
{
	protected Literal ltrTitle;
	protected DropDownList ddlProdcutType;
	protected TextBox txtProductName;
	protected Button SeachBut;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Button btnMoreInStock;
	protected PlaceHolder phManage;
	private string linkHead = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerStockPower(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.BindProductIn();
		}
	}
	protected void BindProductIn()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = "(select SUM(BookCount) from HL_OutStockLog  where NoticeStatue=0 and ProductID=p.ProductID)";
		string text2 = string.Concat(new object[]
		{
			" from HLShop_Product as p where EnableSingleSell=1 and IsDeleted=0 and Stocks<",
			text,
			" and SalerID=",
			base.user.UserID,
			" "
		});
		int pageSize = this.gvManage.PageSize;
		ClientByPage clientByPage = new ClientByPage();
		int listCount = clientByPage.GetListCount("select count(*)" + text2 + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = string.Concat(new string[]
		{
			"ROW_NUMBER() OVER (",
			queryByOrder,
			") as row,p.ProductID,ProductType,ProductSmallImageUrl,ProductName,Stocks,PUnit,StandPrice,",
			text,
			" as BookNum "
		});
		string strSQL = "select " + str + text2 + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		string url = "StockManage/StockInManage.aspx?1=1" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
		for (int i = 0; i < this.gvManage.Rows.Count; i++)
		{
			string text3 = this.gvManage.Rows[i].Cells[4].Text;
			int num2 = Convert.ToInt32(this.gvManage.Rows[i].Cells[5].Text);
			Literal literal = (Literal)this.gvManage.Rows[i].FindControl("ltrAddStock");
			int num3 = 0;
			if (text3 != null)
			{
				num3 = Convert.ToInt32(text3) - num2;
			}
			literal.Text = num3.ToString();
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ProductType");
		if (!string.IsNullOrEmpty(text2))
		{
			for (int i = 0; i < this.ddlProdcutType.Items.Count; i++)
			{
				this.ddlProdcutType.Items[i].Selected = false;
				if (this.ddlProdcutType.Items[i].Value == text2)
				{
					this.ddlProdcutType.Items[i].Selected = true;
					break;
				}
			}
		}
		else
		{
			text2 = this.ddlProdcutType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2) && text2 != "0")
		{
			text = text + " and ProductType=" + text2;
		}
		this.linkHead = this.linkHead + "&ProductType=" + text2;
		string text3 = Fetch.Get("ProductName");
		if (!string.IsNullOrEmpty(text3))
		{
			if (text3 != this.txtProductName.Text.Trim())
			{
				text3 = this.txtProductName.Text.Trim();
			}
			this.txtProductName.Text = text3;
		}
		else
		{
			text3 = this.txtProductName.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and ProductName like '%" + text3 + "%'";
			this.linkHead = this.linkHead + "&ProductName=" + text3;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by p.ProductID desc";
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindProductIn();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		if (commandName == "inStock")
		{
			string text = e.CommandArgument.ToString();
			if (!string.IsNullOrEmpty(text))
			{
				string text2 = "";
				for (int i = 0; i < this.gvManage.Rows.Count; i++)
				{
					int num = Convert.ToInt32(this.gvManage.Rows[i].Cells[1].Text);
					Literal literal = (Literal)this.gvManage.Rows[i].FindControl("ltrAddStock");
					if (num == Convert.ToInt32(text))
					{
						text2 = text + "," + literal.Text;
						break;
					}
				}
				string url = "StockAdd.aspx?Action=addinfo&stockType=inStock&ProductID=" + text + "&ProductIDStock=" + text2;
				base.Response.Redirect(url);
			}
		}
		else
		{
			if (commandName == "MoreInStock")
			{
				string text3 = Text.CheckNumList(Fetch.GetOrPost("SelectId"));
				if (text3 != "")
				{
					string text2 = "";
					string text4 = text3;
					string[] array = text4.Split(new char[]
					{
						','
					});
					for (int i = 0; i < array.Length; i++)
					{
						for (int j = 0; j < this.gvManage.Rows.Count; j++)
						{
							int num = Convert.ToInt32(this.gvManage.Rows[j].Cells[1].Text);
							Literal literal = (Literal)this.gvManage.Rows[j].FindControl("ltrAddStock");
							if (num == Convert.ToInt32(array[i]))
							{
								object obj = text2;
								text2 = string.Concat(new object[]
								{
									obj,
									num,
									",",
									literal.Text,
									"|"
								});
							}
						}
					}
					if (text2 != "")
					{
						text2 = text2.Substring(0, text2.Length - 1);
					}
					string url = "StockAdd.aspx?Action=addinfo&stockType=inStock&ProductID=" + text4 + "&ProductIDStock=" + text2;
					base.Response.Redirect(url);
				}
				else
				{
					this.WriteErrMsg("", "请选择需要补货的商品！", "");
				}
			}
		}
		this.BindProductIn();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindProductIn();
	}
}
